package com.xnew.manager.elevator.detailRules.controller;

import com.xnew.aes.LogParameter;
import com.xnew.bean.common.SysUserInfo;
import com.xnew.manager.elevator.detailRules.entity.DetailRules;
import com.xnew.manager.elevator.detailRules.service.DetailRulesService;
import com.xnew.utils.ConvertEntityUtil;
import com.xnew.utils.DataInput;
import com.xnew.utils.DataOutput;
import com.xnew.utils.UserUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author PuWeiHeng
 * @create 2022-10-25 15:17
 */

@CrossOrigin        //解决跨域异常
@RestController
@Controller("detailRulesController")
public class DetailRulesController {

    @Resource
    private DetailRulesService detailRulesService;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());



    /**
     * 查询 分页查询
     * @author PuWeiHeng
     * @date 2022/10/25
     **/
    @RequestMapping("/pageList")
    public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int offset,
                                        @RequestParam(required = false, defaultValue = "10") int pagesize) {
        return detailRulesService.pageList(offset, pagesize);
    }




    /**
     * @description: 维保细则集合
     * @author: PuWeiHeng
     * @date: 2022/10/25 16:29
     * @param:
     * @return:
    */
    @LogParameter(key = "",desc = "维保细则集合")
    @RequestMapping(value = "/queryDetailRuleList",method = RequestMethod.POST)
    public List<DetailRules> queryDetailRuleList(@RequestBody HttpServletRequest request, DataInput dataInput) {
        DataOutput dataOutput = DataOutput.success();
        SysUserInfo userInfo = UserUtil.getUserInfo(request);
        List<DetailRules> list = null;
        try {
            list = (List<DetailRules>) detailRulesService.queryDetailRuleList(dataInput);
            ConvertEntityUtil.convertListData(list);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            dataOutput.setCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            dataOutput.setMsg("信息填报失败");
        }
        return list;
    }



}
